<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of swiperList" :key="item.id" >
        <img class="swiper-img" :src="item.url">
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default{
  props: {
    swiperList: Array
  },
  name: 'HomeSwiper',
  data () {
    return {
      swiperOption: {
        pagination: {
          el: '.swiper-pagination'
        },
        loop: true,
        autoplay: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.swiperList.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background-color: #ffffff;
  .wrapper /* 设置宽高比始终为31.25%,技巧:设置超出为hidden，height设置为0，padding-bottom相对于width为31.25% */
    overflow: hidden
    width: 100%
    height: 0
    background-color: #eeeeee;
    padding-bottom: 26.7%
    .swiper-img
      width: 100%
</style>
